package com.example.batterynotification;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Looper;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.RingtonePreference;
import android.preference.SwitchPreference;
import android.util.Log;
import android.widget.ArrayAdapter;

public class HighLevelSettingActivity extends PreferenceActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		new Preference(getApplicationContext());
		addPreferencesFromResource(R.layout.high_level_setting_layout);
		
		final Preference ringToneTime = findPreference("RingToneTimePref");
		//set defualt value...............................
		if(Preferences.getStringPreferences("RingToneTimePref")=="30")
			ringToneTime.setSummary("30 seconds");
		else if(Preferences.getStringPreferences("RingToneTimePref")=="1")
			ringToneTime.setSummary("1 minute");
		else if(Preferences.getStringPreferences("RingToneTimePref")=="2")
			ringToneTime.setSummary("2 minutes");
		else if(Preferences.getStringPreferences("RingToneTimePref")=="never")
			ringToneTime.setSummary("Never");
			
		// prepare the dialog ............................
		final String[] option = new String[] { "30 seconds", "1 minute",
				"2 minutes", "Never" };
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.select_dialog_item, option);
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("Select Option");
		builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				switch (which)
				{
				case 0: Preferences.savePreferences("RingToneTimePref", "30");  ringToneTime.setSummary("30 seconds");  break;
				case 1:Preferences.savePreferences("RingToneTimePref", "1");  ringToneTime.setSummary("1 minute");  break;
				case 2: Preferences.savePreferences("RingToneTimePref", "2"); ringToneTime.setSummary("2 minutes"); break;
				case 3: Preferences.savePreferences("RingToneTimePref", "never"); ringToneTime.setSummary("Never"); break;
				}
			}
		});
		final AlertDialog dialog = builder.create();
		// ...............................................
		ringToneTime.setOnPreferenceClickListener(new OnPreferenceClickListener() {
					@Override
					public boolean onPreferenceClick(Preference preference) {
						dialog.show();
						return true;
					}
				});
	}
}
